<!-- 未采用封装 -->
<template>
  <div>
    <!-- 表格区域 -->
    <el-table :data="tableData" v-loading="loading" border style="width: 100%">
      <el-table-column prop="id" label="用户ID" align="center">
      </el-table-column>
      <el-table-column prop="userId" label="所属班级" align="center">
      </el-table-column>
      <el-table-column prop="title" label="作业名称" align="center">
      </el-table-column>
      <el-table-column prop="completed_text" label="完成情况" align="center">
      </el-table-column>
    </el-table>
    <!-- 分页区域 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="page"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      class="pagination"
    >
    </el-pagination>
  </div>
</template>

<script>
import { getData } from '@/utils/table'

export default {
  data () {
    return {
      tableData: [],
      page: 1,
      size: 10,
      total: 0,
      loading: true
    }
  },
  created () {
    getData(this, '/works', { page: this.page, size: this.size }, ['completed'])
  },
  methods: {
    // 分页操作方法
    handleSizeChange (val) {
      this.loading = true
      this.size = val
      this.page = 1
      getData(this, '/works', { page: this.page, size: this.size }, ['completed'])
    },
    handleCurrentChange (val) {
      this.loading = true
      this.page = val
      getData(this, '/works', { page: this.page, size: this.size }, ['completed'])
    },
  }
}
</script>

<style lang="less">
.pagination {
  margin-top: 10px;
}
</style>